﻿CREATE VIEW [dbo].[ASMS_V_StockMaterial]
	AS
SELECT M.Barcode,
	M.Brand,
	M.Category,
	M.Code,
	M.Cost,
	M.CreatedTime,
	M.Creator,
	M.[Description],
	M.Id,
	M.Letter,
	M.Model,
	M.Name,
	M.Pinyin,
	M.Price,
	M.QuickCode,
	M.SalesCommission,
	M.SalesCommissionType,
	M.[Status],
	M.TaxRate,
	M.Unit,
	W.BusinessId, 
	W.StationId, 
	MDIC.Name as CategoryName,
	MDIB.Name as BrandName,
	MDIU.Name as UnitName,
	S.[Count] as StockCount,
	W.[Id] as WarehouseId,
	W.[Name] as WarehouseName
FROM ASMS_Stock as S
	inner join ASMS_Material as M on M.Id = S.MaterialId
	left join ASMS_Warehouse as W on W.id = S.WarehouseId
	left join [ASMS_MasterDataItem] as MDIC on MDIC.Code= M.Category
	left join [ASMS_MasterDataItem] as MDIB on MDIB.Code= M.Brand
	left join [ASMS_MasterDataItem] as MDIU on MDIU.Code= M.Unit